package com.onpositive.dataminer.core;

import com.onpositive.data.IPropertyConstants;
import com.onpositive.semantic.model.api.meta.DefaultMetaKeys;
import com.onpositive.semantic.model.api.meta.IWritableMeta;

public class BasicPropertyMetaAcessor {

	protected IWritableMeta meta;

	public BasicPropertyMetaAcessor( IWritableMeta meta) {
		super();
		this.meta = meta;
	}

	public String getId() {
		return DefaultMetaKeys.getValue(meta, DefaultMetaKeys.ID_KEY,
				String.class);
	}
	public void doAudit(){
		
	}

	public boolean isRequired() {
		return DefaultMetaKeys.isRequired(meta);
	}

	public void setRequired(boolean req) {
		meta.putMeta(DefaultMetaKeys.REQUIRED_KEY, req);
	}

	public boolean isMultivalue() {
		return DefaultMetaKeys.isMultivalue(meta);
	}

	public void setMultivalue(boolean req) {
		meta.putMeta(DefaultMetaKeys.MULTI_VALUE_KEY, req);
	}

	public boolean isSimmetric() {
		return DefaultMetaKeys
				.getValue(meta, "simmetric", Boolean.class, false);
	}

	public void setSimmetric(boolean req) {
		meta.putMeta("simmetric", req);
	}

	public boolean isTransitive() {
		return DefaultMetaKeys.getValue(meta, "transitive", Boolean.class,
				false);
	}

	public void setTransitive(boolean req) {
		meta.putMeta("transitive", req);
	}
	
	

	public boolean isFixedBound() {
		return DefaultMetaKeys.getValue(meta, DefaultMetaKeys.FIXED_BOUND_KEY,
				Boolean.class, false);
	}

	public void setFixedBound(boolean req) {
		meta.putMeta(DefaultMetaKeys.FIXED_BOUND_KEY, req);
	}

	public boolean isDepricated() {
		return DefaultMetaKeys.getValue(meta, IPropertyConstants.CHAR_DEPRICATED_LABEL, Boolean.class,
				false);
	}

	public void setDepricated(boolean req) {
		meta.putMeta(IPropertyConstants.CHAR_DEPRICATED_LABEL, req);
	}

	public boolean isImportant() {
		return DefaultMetaKeys
				.getValue(meta, "important", Boolean.class, false);
	}

	public void setImportant(boolean req) {
		meta.putMeta("important", req);
	}

	public String getDescription() {
		return DefaultMetaKeys.getValue(meta, DefaultMetaKeys.DESCRIPTION_KEY,
				String.class);
	}

	public void setDescription(String desc) {
		doSet(DefaultMetaKeys.DESCRIPTION_KEY, desc);
	}

	public String getName() {
		return DefaultMetaKeys.getValue(meta, DefaultMetaKeys.NAME_KEY,
				String.class);
	}

	public void setName(String value) {
		doSet(DefaultMetaKeys.NAME_KEY, value);
	}
	
	public String getUnit(){
		return DefaultMetaKeys.getValue(meta,IPropertyConstants.CHAR_PRIMARY_UNIT_LABEL, String.class, null);
	}
	public void setUnit(String value){
		doSet(IPropertyConstants.CHAR_PRIMARY_UNIT_LABEL, value);
	}

	public String getRange(){
		return DefaultMetaKeys.getValue(meta,IPropertyConstants.CHAR_PARSER_ID_LABEL, String.class, null);
	}
	public void setRange(String value){
		doSet(IPropertyConstants.CHAR_PARSER_ID_LABEL, value);
	}
	
	private void doSet(String key, String value) {
		if(value==null||value.trim().isEmpty()){
			meta.putMeta(key, null);
		}
		else{
			meta.putMeta(key, value);
		}		
	}
}
